import Vue from 'vue'
import App from './App.vue'
import router from './router'
import axios from 'axios'

// 设置 axios 默认配置
axios.defaults.headers.post['Content-Type'] = 'application/json'
axios.defaults.headers.put['Content-Type'] = 'application/json'
axios.defaults.headers.patch['Content-Type'] = 'application/json'

// 将 axios 添加到 Vue 原型上，方便在组件中使用
Vue.prototype.$http = axios

// 全局错误处理 - 抑制 ResizeObserver 错误
const resizeObserverErrorHandler = (e) => {
  if (e.message && e.message.includes('ResizeObserver loop completed with undelivered notifications')) {
    return true
  }
  if (e.error && e.error.message && e.error.message.includes('ResizeObserver loop completed with undelivered notifications')) {
    return true
  }
  return false
}

// 处理全局错误事件
window.addEventListener('error', (e) => {
  if (resizeObserverErrorHandler(e)) {
    e.preventDefault()
    e.stopPropagation()
    return false
  }
})

// 处理未捕获的Promise错误
window.addEventListener('unhandledrejection', (e) => {
  if (e.reason && e.reason.message && e.reason.message.includes('ResizeObserver loop completed with undelivered notifications')) {
    e.preventDefault()
    return false
  }
})

// 重写console.error以过滤ResizeObserver错误
const originalConsoleError = console.error
console.error = function(...args) {
  if (args.length > 0 && typeof args[0] === 'string' && args[0].includes('ResizeObserver loop completed with undelivered notifications')) {
    return
  }
  originalConsoleError.apply(console, args)
}

Vue.config.productionTip = false

new Vue({
  router,
  render: h => h(App),
}).$mount('#app')
